package com.biwin.core.main.interceptor;

import com.biwin.core.api.interceptor.IBwHandlerInterceptor;
import com.biwin.core.api.vo.OnlineUserInfoVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * TODO
 *
 * @author biwin
 * @since 0.0.1
 */
@Component
public class BwHandlerInterceptor extends HandlerInterceptorAdapter implements IBwHandlerInterceptor {
    private static final Logger log = LoggerFactory.getLogger(BwHandlerInterceptor.class);

    /**
     * This implementation always returns {@code true}.
     *
     * @param request
     * @param response
     * @param handler
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if(log.isInfoEnabled()){
            log.info("开始执行框架定义的拦截器...");
        }

//        setCurrentUser();
        return super.preHandle(request, response, handler);

    }

    /**
     * This implementation is empty.
     *
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        log.info("开始执行后置处理");
        super.postHandle(request, response, handler, modelAndView);
    }

}
